﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace Manox.Libs.ODB
{
    /// <summary>
    /// Object database item base.
    /// </summary>
    public abstract class ObjectDatabaseItemBase : IDisposable
    {
        /// <summary>Id.</summary>
        internal Guid Id;


        /// <summary>
        /// Constructor.
        /// </summary>
        public ObjectDatabaseItemBase()
        {
            this.Id = Guid.Empty;
        }

        /// <summary>
        /// Dispose.
        /// </summary>
        public virtual void Dispose()
        {

        }
    }

    /// <summary>
    /// Object database proxy.
    /// </summary>
    public class ObjectDatabaseItemProxy : ObjectDatabaseItemBase
    {
    }

    /// <summary>
    /// Object database item.
    /// </summary>
    [Serializable]
    public abstract class ObjectDatabaseItem : ObjectDatabaseItemBase
    {
        /// <summary>Data changed.</summary>
        public event ObjectDataChangedCallback DataChanged;


        /// <summary>
        /// Constructor.
        /// </summary>
        public ObjectDatabaseItem()
            : base()
        {
            
        }

        /// <summary>
        /// Call data changed event.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        public void CallDataChangedEvent(object sender, ObjectDatabaseEventArgs eventArgs)
        {
            if (this.DataChanged != null)
                this.DataChanged(sender, eventArgs);
        }

        /// <summary>
        /// Initialize in ODB.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="odbManager"></param>
        public abstract void InitializeInODB(object sender, ObjectDatabaseManager odbManager);

        /// <summary>
        /// Initializing EventArgs.
        /// </summary>
        /// <returns></returns>
        public abstract List<ObjectDatabaseEventArgs> InitializingEventArgs();

        /// <summary>
        /// Is finished.
        /// </summary>
        /// <returns></returns>
        public virtual bool IsFinished()
        {
            return true;
        }
    }    

    /// <summary>
    /// Object data changed callback.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="eventArgs"></param>
    public delegate void ObjectDataChangedCallback(object sender, ObjectDatabaseEventArgs eventArgs);    
}
